import request from '@/config/axios';
import type { Dayjs } from 'dayjs';

/** 栋信息 */
export interface Buildings {
          id: number; // id
          buildingName?: string; // 楼栋名
          nickName: string; // 昵称
          campus?: number; // 校区名称：校本部1；文创园2；科创园3
          totalFloors?: number; // 总楼层
          totalRooms: number; // 总房间数
          charger: number; // 楼管
          buildDate: string | Dayjs; // 建造日期
  }

// 栋 API
export const BuildingsApi = {
  // 查询栋分页
  getBuildingsPage: async (params: any) => {
    return await request.get({ url: `/dorm/buildings/page`, params })
  },

  // 查询栋详情
  getBuildings: async (id: number) => {
    return await request.get({ url: `/dorm/buildings/get?id=` + id })
  },

  // 新增栋
  createBuildings: async (data: Buildings) => {
    return await request.post({ url: `/dorm/buildings/create`, data })
  },

  // 修改栋
  updateBuildings: async (data: Buildings) => {
    return await request.put({ url: `/dorm/buildings/update`, data })
  },

  // 删除栋
  deleteBuildings: async (id: number) => {
    return await request.delete({ url: `/dorm/buildings/delete?id=` + id })
  },

  /** 批量删除栋 */
  deleteBuildingsList: async (ids: number[]) => {
    return await request.delete({ url: `/dorm/buildings/delete-list?ids=${ids.join(',')}` })
  },

  // 导出栋 Excel
  exportBuildings: async (params) => {
    return await request.download({ url: `/dorm/buildings/export-excel`, params })
  },
  
  // 获取所有楼栋（带s的版本，兼容GatewaysForm.vue的使用）
  getBuildingsAll: async () => {
    return await request.get({ url: `/dorm/buildings/all` })
  },
}
